<template>
	<view>
		<view class="bg-white padding">
			<u-form labelPosition="top" :model="feedback" ref="uFrom" :rules="rules" :labelWidth="180">
				<u-form-item :label="feedback.feedbackTitle" prop="feedbackContent" required>
					<u-textarea  v-model="feedback.feedbackContent" placeholder="请填写10个字以上的问题描述以便我们提供更好的帮助" confirmType="done" count maxlength="500"></u-textarea>
				</u-form-item>
				<u-form-item label="截图 (最多5张)" prop="feedbackAttach">
					<ImageUpload v-model="feedback.feedbackAttach" :limit="5"></ImageUpload>
				</u-form-item> 
<!-- 				 <u-form-item label="联系人" prop="contactName" required>
					<u-input v-model="feedback.contactName" placeholder="请输入您的姓名">
					</u-input>
				</u-form-item>
				 <u-form-item label="联系电话" prop="contactPhone" required>
					<u-input v-model="feedback.contactPhone" placeholder="请输入您的电话">
					</u-input>
				</u-form-item> -->
			</u-form>
			<view class="padding">
				<button class="cu-btn block bg-blue margin-tb-sm lg round" @click="submit()">确认</button>
			</view>
		</view>
	</view>
</template>

<script>
	import { feedback, feedbackDetail } from '@/api/cms.js'
	export default {
		data() {
			return {
				id: 0,
				feedbackTitle: "",
				feedback: {
					feedbackType: 0,
					feedbackTitle: "",
					feedbackContent: "",
					feedbackAttach: "",
				},
				picsList: [],
				rules: {
					feedbackContent: {
						type: 'string',
						min: 10,
						required: true,
						message: '请用10个以上的文字描述',
						trigger: ['change']
					},
					// contactPhone: {
					// 	type: 'string',
					// 	len: 11,
					// 	required: true,
					// 	message: '请输入正确的电话号码',
					// 	trigger: ['change']
					// },
				}
			}
		},
		onLoad(options) {
			this.feedback.feedbackTitle = options.feedbackTitle;
			this.feedback.feedbackType = options.feedbackType;
			
			if (options.id) {
				this.id = options.id
				this.getFeedbackDetail();
			}
		},
		methods: {
			// 获取反馈详情
			getFeedbackDetail() {
				feedbackDetail({
					feedbackId: this.id
				}).then(res => {
					this.feedback = res.data;
				})
			},
			
			// 提交表单
			submit() {
				let that = this;
				this.$refs.uFrom.validate().then(res => {
					this.$util.$confirm("是否确认提交？").then(res => {
						that.confirm();
					})
				}).catch(err => {
					
				})
			},
			confirm() {
				feedback(this.feedback).then(res => {
					this.$util.$switchTab(res.msg, '/pages/mine/mine');
				})
			}
		}
	}
</script>

<style>

</style>
